home *** CD-ROM | disk | FTP | other *** search
/ Aminet 19 / Aminet 19 (1997)(GTI - Schatztruhe)[!][Jun 1997].iso / Aminet / comm / net / ARemote1_00B.lha / ARemote / source / ARemote.c < prev    next >
C/C++ Source or Header  |  1997-04-27  |  9KB  |  303 lines

  1. /*
  2.  *  Source machine generated by GadToolsBox V2.0b
  3.  *  which is (c) Copyright 1991-1993 Jaba Development
  4.  *
  5.  *  GUI Designed by : Jeremy Friesner
  6.  */
  7.  
  8. #include <exec/types.h>
  9. #include <intuition/intuition.h>
  10. #include <intuition/classes.h>
  11. #include <intuition/classusr.h>
  12. #include <intuition/imageclass.h>
  13. #include <intuition/gadgetclass.h>
  14. #include <libraries/gadtools.h>
  15. #include <graphics/displayinfo.h>
  16. #include <graphics/gfxbase.h>
  17. #include <clib/exec_protos.h>
  18. #include <clib/intuition_protos.h>
  19. #include <clib/gadtools_protos.h>
  20. #include <clib/graphics_protos.h>
  21. #include <clib/utility_protos.h>
  22. #include <string.h>
  23. #include "ARemote.h"
  24.  
  25. struct Screen         *Scr = NULL;
  26. UBYTE                 *PubScreenName = "Workbench";
  27. APTR                   VisualInfo = NULL;
  28. struct Window         *ARemoteWnd = NULL;
  29. struct Gadget         *ARemoteGList = NULL;
  30. struct Menu           *ARemoteMenus = NULL;
  31. struct IntuiMessage    ARemoteMsg;
  32. struct Gadget         *ARemoteGadgets[12];
  33. UWORD                  ARemoteLeft = 119;
  34. UWORD                  ARemoteTop = 66;
  35. UWORD                  ARemoteWidth = 318;
  36. UWORD                  ARemoteHeight = 189;
  37. UBYTE                 *ARemoteWdt = (UBYTE *)"ARemote";
  38. struct TextAttr       *Font, Attr;
  39. UWORD                  FontX, FontY;
  40. UWORD                  OffX, OffY;
  41.  
  42. struct NewMenu ARemoteNewMenu[] = {
  43.     NM_TITLE, (STRPTR)"Project", NULL, 0, NULL, NULL,
  44.     NM_ITEM, (STRPTR)"About", (STRPTR)"A", 0, 0L, (APTR)ARemoteAbout,
  45.     NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
  46.     NM_ITEM, (STRPTR)"Enabled", (STRPTR)"E", CHECKIT, 0L, (APTR)ARemoteEnabled,
  47.     NM_ITEM, (STRPTR)"Save Settings", (STRPTR)"S", 0, 0L, (APTR)ARemoteSaveSettings,
  48.     NM_ITEM, (STRPTR)"Hide", (STRPTR)"H", 0, 0L, (APTR)ARemoteHide,
  49.     NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
  50.     NM_ITEM, (STRPTR)"Quit", (STRPTR)"Q", 0, 0L, (APTR)ARemoteQuit,
  51.     NM_END, NULL, NULL, 0, 0L, NULL };
  52.  
  53. UWORD ARemoteGTypes[] = {
  54.     STRING_KIND,
  55.     STRING_KIND,
  56.     INTEGER_KIND,
  57.     INTEGER_KIND,
  58.     STRING_KIND,
  59.     STRING_KIND,
  60.     STRING_KIND,
  61.     CHECKBOX_KIND,
  62.     BUTTON_KIND,
  63.     BUTTON_KIND,
  64.     CHECKBOX_KIND,
  65.     STRING_KIND
  66. };
  67.  
  68. struct NewGadget ARemoteNGad[] = {
  69.     98, 8, 211, 16, (UBYTE *)"C_onnect To", NULL, GD_ConnectToString, PLACETEXT_LEFT, NULL, (APTR)ConnectToStringClicked,
  70.     104, 65, 205, 16, (UBYTE *)"_Accept From", NULL, GD_AcceptFromString, PLACETEXT_LEFT, NULL, (APTR)AcceptFromStringClicked,
  71.     49, 29, 65, 16, (UBYTE *)"_Port", NULL, GD_ConnectToPortInt, PLACETEXT_LEFT, NULL, (APTR)ConnectToPortIntClicked,
  72.     48, 85, 65, 16, (UBYTE *)"Po_rt", NULL, GD_AcceptFromPortInt, PLACETEXT_LEFT, NULL, (APTR)AcceptFromPortIntClicked,
  73.     111, 131, 203, 16, (UBYTE *)"_Xmit Trigger", NULL, GD_ToggleString, PLACETEXT_LEFT, NULL, (APTR)ToggleStringClicked,
  74.     195, 29, 114, 16, (UBYTE *)"Pas_sword", NULL, GD_ConnectToPasswordString, PLACETEXT_LEFT, NULL, (APTR)ConnectToPasswordStringClicked,
  75.     195, 85, 114, 16, (UBYTE *)"Pass_word", NULL, GD_AcceptFromPasswordString, PLACETEXT_LEFT, NULL, (APTR)AcceptFromPasswordStringClicked,
  76.     159, 153, 26, 11, (UBYTE *)"Co_nnect on Startup", NULL, GD_ConnectOnStartupCheckbox, PLACETEXT_LEFT, NULL, (APTR)ConnectOnStartupCheckboxClicked,
  77.     4, 169, 149, 16, (UBYTE *)"_Connect Now", NULL, GD_ConnectButton, PLACETEXT_IN, NULL, (APTR)ConnectButtonClicked,
  78.     160, 169, 153, 16, (UBYTE *)"_Disconnect Now", NULL, GD_DisconnectButton, PLACETEXT_IN, NULL, (APTR)DisconnectButtonClicked,
  79.     279, 153, 26, 11, (UBYTE *)"_Flash LED", NULL, GD_XmitCueCheckbox, PLACETEXT_LEFT, NULL, (APTR)XmitCueCheckboxClicked,
  80.     111, 111, 203, 16, (UBYTE *)"Pop_up Hotkey", NULL, GD_PopupHotkeyString, PLACETEXT_LEFT, NULL, (APTR)PopupHotkeyStringClicked
  81. };
  82.  
  83. ULONG ARemoteGTags[] = {
  84.     (GTST_MaxChars), 256, (GT_Underscore), '_', (TAG_DONE),
  85.     (GTST_MaxChars), 256, (GT_Underscore), '_', (TAG_DONE),
  86.     (GTIN_Number), 0, (GTIN_MaxChars), 10, (GT_Underscore), '_', (TAG_DONE),
  87.     (GTIN_Number), 0, (GTIN_MaxChars), 10, (GT_Underscore), '_', (TAG_DONE),
  88.     (GTST_MaxChars), 256, (GT_Underscore), '_', (TAG_DONE),
  89.     (GTST_MaxChars), 256, (GT_Underscore), '_', (TAG_DONE),
  90.     (GTST_MaxChars), 256, (GT_Underscore), '_', (TAG_DONE),
  91.     (GT_Underscore), '_', (TAG_DONE),
  92.     (GT_Underscore), '_', (TAG_DONE),
  93.     (GT_Underscore), '_', (TAG_DONE),
  94.     (GT_Underscore), '_', (TAG_DONE),
  95.     (GTST_MaxChars), 256, (GT_Underscore), '_', (TAG_DONE)
  96. };
  97.  
  98. static UWORD ComputeX( UWORD value )
  99. {
  100.     return(( UWORD )((( FontX * value ) + 4 ) / 8 ));
  101. }
  102.  
  103. static UWORD ComputeY( UWORD value )
  104. {
  105.     return(( UWORD )((( FontY * value ) + 4 ) / 8 ));
  106. }
  107.  
  108. static void ComputeFont( UWORD width, UWORD height )
  109. {
  110.     Font = &Attr;
  111.     Font->ta_Name = (STRPTR)Scr->RastPort.Font->tf_Message.mn_Node.ln_Name;
  112.     Font->ta_YSize = FontY = Scr->RastPort.Font->tf_YSize;
  113.     FontX = Scr->RastPort.Font->tf_XSize;
  114.  
  115.     OffX = Scr->WBorLeft;
  116.     OffY = Scr->RastPort.TxHeight + Scr->WBorTop + 1;
  117.  
  118.     if ( width && height ) {
  119.         if (( ComputeX( width ) + OffX + Scr->WBorRight ) > Scr->Width )
  120.             goto UseTopaz;
  121.         if (( ComputeY( height ) + OffY + Scr->WBorBottom ) > Scr->Height )
  122.             goto UseTopaz;
  123.     }
  124.     return;
  125.  
  126. UseTopaz:
  127.     Font->ta_Name = (STRPTR)"topaz.font";
  128.     FontX = FontY = Font->ta_YSize = 8;
  129. }
  130.  
  131. int SetupScreen( void )
  132. {
  133.     if ( ! ( Scr = LockPubScreen( PubScreenName )))
  134.         return( 1L );
  135.  
  136.     ComputeFont( 0, 0 );
  137.  
  138.     if ( ! ( VisualInfo = GetVisualInfo( Scr, TAG_DONE )))
  139.         return( 2L );
  140.  
  141.     return( 0L );
  142. }
  143.  
  144. void CloseDownScreen( void )
  145. {
  146.     if ( VisualInfo ) {
  147.         FreeVisualInfo( VisualInfo );
  148.         VisualInfo = NULL;
  149.     }
  150.  
  151.     if ( Scr        ) {
  152.         UnlockPubScreen( NULL, Scr );
  153.         Scr = NULL;
  154.     }
  155. }
  156.  
  157. void ARemoteRender( void )
  158. {
  159.     ComputeFont( ARemoteWidth, ARemoteHeight );
  160.  
  161.     DrawBevelBox( ARemoteWnd->RPort, OffX + ComputeX( 3 ),
  162.                     OffY + ComputeY( 58 ),
  163.                     ComputeX( 311 ),
  164.                     ComputeY( 48 ),
  165.                     GT_VisualInfo, VisualInfo, TAG_DONE );
  166.     DrawBevelBox( ARemoteWnd->RPort, OffX + ComputeX( 3 ),
  167.                     OffY + ComputeY( 3 ),
  168.                     ComputeX( 311 ),
  169.                     ComputeY( 51 ),
  170.                     GT_VisualInfo, VisualInfo, TAG_DONE );
  171. }
  172.  
  173. int HandleARemoteIDCMP( void )
  174. {
  175.     struct IntuiMessage    *m;
  176.     struct MenuItem        *n;
  177.     int            (*func)();
  178.     BOOL            running = TRUE;
  179.  
  180.     while( m = GT_GetIMsg( ARemoteWnd->UserPort )) {
  181.  
  182.         CopyMem(( char * )m, ( char * )&ARemoteMsg, (long)sizeof( struct IntuiMessage ));
  183.  
  184.         GT_ReplyIMsg( m );
  185.  
  186.         switch ( ARemoteMsg.Class ) {
  187.  
  188.             case    IDCMP_REFRESHWINDOW:
  189.                 GT_BeginRefresh( ARemoteWnd );
  190.                 ARemoteRender();
  191.                 GT_EndRefresh( ARemoteWnd, TRUE );
  192.                 break;
  193.  
  194.             case    IDCMP_CLOSEWINDOW:
  195.                 running = ARemoteCloseWindow();
  196.                 break;
  197.  
  198.             case    IDCMP_VANILLAKEY:
  199.                 running = ARemoteVanillaKey();
  200.                 break;
  201.  
  202.             case    IDCMP_GADGETUP:
  203.             case    IDCMP_GADGETDOWN:
  204.                 func = ( void * )(( struct Gadget * )ARemoteMsg.IAddress )->UserData;
  205.                 running = func();
  206.                 break;
  207.  
  208.             case    IDCMP_MENUPICK:
  209.                 while( ARemoteMsg.Code != MENUNULL ) {
  210.                     n = ItemAddress( ARemoteMenus, ARemoteMsg.Code );
  211.                     func = (void *)(GTMENUITEM_USERDATA( n ));
  212.                     running = func();
  213.                     ARemoteMsg.Code = n->NextSelect;
  214.                 }
  215.                 break;
  216.         }
  217.     }
  218.     return( running );
  219. }
  220.  
  221. int OpenARemoteWindow( void )
  222. {
  223.     struct NewGadget    ng;
  224.     struct Gadget    *g;
  225.     UWORD        lc, tc;
  226.     UWORD        wleft = ARemoteLeft, wtop = ARemoteTop, ww, wh;
  227.  
  228.     ComputeFont( ARemoteWidth, ARemoteHeight );
  229.  
  230.     ww = ComputeX( ARemoteWidth );
  231.     wh = ComputeY( ARemoteHeight );
  232.  
  233.     if (( wleft + ww + OffX + Scr->WBorRight ) > Scr->Width ) wleft = Scr->Width - ww;
  234.     if (( wtop + wh + OffY + Scr->WBorBottom ) > Scr->Height ) wtop = Scr->Height - wh;
  235.  
  236.     if ( ! ( g = CreateContext( &ARemoteGList )))
  237.         return( 1L );
  238.  
  239.     for( lc = 0, tc = 0; lc < ARemote_CNT; lc++ ) {
  240.  
  241.         CopyMem((char * )&ARemoteNGad[ lc ], (char * )&ng, (long)sizeof( struct NewGadget ));
  242.  
  243.         ng.ng_VisualInfo = VisualInfo;
  244.         ng.ng_TextAttr   = Font;
  245.         ng.ng_LeftEdge   = OffX + ComputeX( ng.ng_LeftEdge );
  246.         ng.ng_TopEdge    = OffY + ComputeY( ng.ng_TopEdge );
  247.         ng.ng_Width      = ComputeX( ng.ng_Width );
  248.         ng.ng_Height     = ComputeY( ng.ng_Height);
  249.  
  250.         ARemoteGadgets[ lc ] = g = CreateGadgetA((ULONG)ARemoteGTypes[ lc ], g, &ng, ( struct TagItem * )&ARemoteGTags[ tc ] );
  251.  
  252.         while( ARemoteGTags[ tc ] ) tc += 2;
  253.         tc++;
  254.  
  255.         if ( NOT g )
  256.             return( 2L );
  257.     }
  258.  
  259.     if ( ! ( ARemoteMenus = CreateMenus( ARemoteNewMenu, GTMN_FrontPen, 0L, TAG_DONE )))
  260.         return( 3L );
  261.  
  262.     LayoutMenus( ARemoteMenus, VisualInfo, TAG_DONE );
  263.  
  264.     if ( ! ( ARemoteWnd = OpenWindowTags( NULL,
  265.                 WA_Left,    wleft,
  266.                 WA_Top,        wtop,
  267.                 WA_Width,    ww + OffX + Scr->WBorRight,
  268.                 WA_Height,    wh + OffY + Scr->WBorBottom,
  269.                 WA_IDCMP,    STRINGIDCMP|INTEGERIDCMP|CHECKBOXIDCMP|BUTTONIDCMP|IDCMP_GADGETDOWN|IDCMP_MENUPICK|IDCMP_CLOSEWINDOW|IDCMP_VANILLAKEY|IDCMP_REFRESHWINDOW,
  270.                 WA_Flags,    WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SIZEBBOTTOM|WFLG_SMART_REFRESH|WFLG_ACTIVATE,
  271.                 WA_Gadgets,    ARemoteGList,
  272.                 WA_Title,    ARemoteWdt,
  273.                 WA_ScreenTitle,    "ARemote",
  274.                 TAG_DONE )))
  275.     return( 4L );
  276.  
  277.     SetMenuStrip( ARemoteWnd, ARemoteMenus );
  278.     GT_RefreshWindow( ARemoteWnd, NULL );
  279.  
  280.     ARemoteRender();
  281.  
  282.     return( 0L );
  283. }
  284.  
  285. void CloseARemoteWindow( void )
  286. {
  287.     if ( ARemoteMenus      ) {
  288.         ClearMenuStrip( ARemoteWnd );
  289.         FreeMenus( ARemoteMenus );
  290.         ARemoteMenus = NULL;    }
  291.  
  292.     if ( ARemoteWnd        ) {
  293.         CloseWindow( ARemoteWnd );
  294.         ARemoteWnd = NULL;
  295.     }
  296.  
  297.     if ( ARemoteGList      ) {
  298.         FreeGadgets( ARemoteGList );
  299.         ARemoteGList = NULL;
  300.     }
  301. }
  302.  
  303.